/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package seGobangClient.uiSystem2D;

import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import seGobangResources.PathRes;

/**
 *
 * @author Leo
 */
public class MyButton extends JButton implements MouseListener
{

    private ImageIcon icon1,  icon2;
    private PathRes path = new PathRes();

    public MyButton(String key1, String key2, int w, int h)
    {
        try
        {
            icon1 = new ImageIcon(path.getPath(key1));
            icon1.setImage(icon1.getImage().getScaledInstance(w, h, Image.SCALE_DEFAULT));
            icon2 = new ImageIcon(path.getPath(key2));
            icon2.setImage(icon2.getImage().getScaledInstance(w, h, Image.SCALE_DEFAULT));
            this.setIcon(icon1);
            this.addMouseListener(this);
        } catch (Exception e)
        {

        }
    }

    public void setValid(boolean valid)
    {
        if (!valid)
        {
            this.setEnabled(false);
            this.setDisabledIcon(icon1);
        } else
        {
            this.setEnabled(true);
        }
    }

    public void mouseEntered(MouseEvent me)
    {
    }

    public void mouseExited(MouseEvent me)
    {
    }

    public void mousePressed(MouseEvent me)
    {
        this.setIcon(icon2);
    }

    public void mouseReleased(MouseEvent me)
    {
        this.setIcon(icon1);
    }

    public void mouseClicked(MouseEvent me)
    {

    }
}
